package com.sgcc.statistics.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.sgcc.statistics.domain.dto.IndexMapBindDto;
import com.sgcc.statistics.domain.dto.IndexMapBindExDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.statistics.domain.OOperationIndex;
import com.sgcc.statistics.service.IOOperationIndexService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * OOperationIndexController
 *
 * @author sgcc
 * @date 2021-04-13
 */
@RestController
@RequestMapping("/operationIndex")
public class OOperationIndexController extends BaseController {
    @Autowired
    private IOOperationIndexService oOperationIndexService;

    /**
     * 查询OOperationIndex列表
     */
    //@PreAuthorize(hasPermi = "statistics:index:list")
    @GetMapping("/list")
    public TableDataInfo list(OOperationIndex oOperationIndex) {
        startPage();
        List<OOperationIndex> list = oOperationIndexService.selectOOperationIndexList(oOperationIndex);
        return getDataTable(list);
    }

    /**
     * 导出OOperationIndex列表
     */
    //@PreAuthorize(hasPermi = "statistics:index:export")
    @Log(title = "OOperationIndex", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OOperationIndex oOperationIndex) throws IOException {
        List<OOperationIndex> list = oOperationIndexService.selectOOperationIndexList(oOperationIndex);
        ExcelUtil<OOperationIndex> util = new ExcelUtil<OOperationIndex>(OOperationIndex.class);
        util.exportExcel(response, list, "index");
    }

    /**
     * 获取OOperationIndex详细信息
     */
    //@PreAuthorize(hasPermi = "statistics:index:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(oOperationIndexService.selectOOperationIndexById(id));
    }

    /**
     * 新增OOperationIndex
     */
    //@PreAuthorize(hasPermi = "statistics:index:add")
    @Log(title = "OOperationIndex", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OOperationIndex oOperationIndex) {
        return toAjax(oOperationIndexService.insertOOperationIndex(oOperationIndex));
    }

    /**
     * 修改OOperationIndex
     */
    //@PreAuthorize(hasPermi = "statistics:index:edit")
    @Log(title = "OOperationIndex", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OOperationIndex oOperationIndex) {
        return toAjax(oOperationIndexService.updateOOperationIndex(oOperationIndex));
    }

    /**
     * 删除OOperationIndex
     */
    //@PreAuthorize(hasPermi = "statistics:index:remove")
    @Log(title = "OOperationIndex", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(oOperationIndexService.deleteOOperationIndexByIds(ids));
    }


    /**
     * 运营看板总览地图绑定量
     *
     * @param orgNo
     * @param statisticalTime
     * @return
     * @author chensong
     * @version 2020-11-02
     */

    @GetMapping(value = "indexMapBind")
    public AjaxResult indexMapBind(String orgNo,
                                   String statisticalTime) {
        try {
            Map<String, Object> condition = new HashMap<>();
            condition.put("orgNo", orgNo);
            condition.put("statisticalTime", statisticalTime);
            List<IndexMapBindExDto> result = oOperationIndexService.indexMapBind(condition);
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("查询运营看板总览地图绑定量失败！失败信息：" + e.getMessage());
        }
    }


}
